//
//  HMNewFeatureCollectionCell.m
//  SinaWeiBo
//
//  Created by WGP on 16/4/12.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "HMNewFeatureCollectionCell.h"

@interface HMNewFeatureCollectionCell ()

@property(nonatomic,weak)UIImageView *bgImageView;
@property(nonatomic,weak)UIButton *startBtn;

@end

@implementation HMNewFeatureCollectionCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self setupSubviews];
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if(self = [super initWithCoder:aDecoder])
    {
        [self setupSubviews];
    }
    return self;
}


-(void)setupSubviews
{
//    1.添加
    UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"new_feature_1"]];
    self.bgImageView = bgImageView;
    [self.contentView addSubview:bgImageView];
    
    UIButton *startBtn = [[UIButton alloc] init];
    self.startBtn = startBtn;
    
    [startBtn setTitle:@"开始体验" forState:UIControlStateNormal];
    [startBtn sizeToFit];
    startBtn.titleLabel.font = HMNewFeatureBtnFont;
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    [self.contentView addSubview:startBtn];
    
//    2.添加约束
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(-160);
    }];
}

-(void)setIndex:(NSInteger)index
{
    _index = index;
    self.startBtn.hidden  =YES;
    NSString *imageName = [NSString stringWithFormat:@"new_feature_%zd",index+1];
    self.bgImageView.image = [UIImage imageNamed:imageName];
  
    
}

-(void)startAnimation
{
    self.startBtn.transform = CGAffineTransformMakeScale(0, 0);
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:5 options:0 animations:^{
        
        self.startBtn.hidden = NO;
        self.startBtn.transform = CGAffineTransformIdentity;
        
    } completion:^(BOOL finished) {
        
    }];
}

@end




















